package fr.oz.mobile.module.profile.day 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import fr.digitas.flowearth.conf.Conf;
	import fr.oz.core.datas.ProfilListDatas;
	import fr.oz.mobile.common.ui.SelectButton;
	import fr.oz.mobile.module.IView;
	import fr.oz.view.profile.ColorSelectorView;
	/**
	 * ...
	 * @author Fazermokeur
	 */
	public class ColorSelector extends Sprite implements IView
	{
		private var setButton:SelectButton;
		private var view:ColorSelectorView;
		private var profil:ProfilListDatas;
		
		
		public function ColorSelector(_profil:ProfilListDatas) 
		{
			addEventListener(Event.ADDED_TO_STAGE, init);
		
			profil = _profil;
			
			setButton = new SelectButton();
			addChild(setButton);
		}
		
		private function init(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			addEventListener(Event.REMOVED_FROM_STAGE, dispose);
			
			view = new ColorSelectorView(profil);
			addChild(view);
			
			setButton.y = stage.stageHeight - 90;
			setButton.x = (stage.stageWidth - setButton.width) >> 1;
			setButton.addEventListener(MouseEvent.CLICK, handleClick);
			addChild(setButton);
		}
		
		private function handleClick(e:MouseEvent):void 
		{
			trace("handleCLCIK SET BUTTON");
			profil.color = view.constructColor();
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		private function dispose(e:Event):void 
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, dispose);
		}
		
		/* INTERFACE fr.oz.mobile.module.IView */
		
		public function getValue():ProfilListDatas
		{
			return profil;
		}
		
		public function removeView():void
		{
			
		}
		
		public function activeView():void
		{
			
		}
		
		public function get title():XMLList
		{
			return Conf.getDatas("wakeUpProfile").data.ui.wakeUpColor;
		}
		
		public function get cachePosY():int
		{
			return 120;
		}
		
	}

}